#ifndef __BSP_UART_H__
#define __BSP_UART_H__

#ifdef __cplusplus
extern "C" {
#endif

#define BSP_UART_CHANNEL0_NAME           "/dev/ttyS1"

typedef enum __BSP_UART_CHANNEL_e__
{
    BSP_UART_CHANNEL_0 = 0,

    BSP_UART_CHANNEL_MAX,
} BSP_UART_CHANNEL_e;

typedef enum _UART_BAUD_RATE_e_
{
    UART_BAUD_RATE_B300 = 1,
    UART_BAUD_RATE_B1200,
    UART_BAUD_RATE_B2400,
    UART_BAUD_RATE_B4800,
    UART_BAUD_RATE_B9600,
    UART_BAUD_RATE_B19200,
    UART_BAUD_RATE_B38400,
    UART_BAUD_RATE_B57600,
    UART_BAUD_RATE_B115200,

    UART_BAUD_RATE_MAX,
} UART_BAUD_RATE_e;

typedef enum _UART_DATA_BITS_e_
{
    UART_DATA_BITS_5 = 1,
    UART_DATA_BITS_6,
    UART_DATA_BITS_7,
    UART_DATA_BITS_8,

    UART_DATA_BITS_MAX,
} UART_DATA_BITS_e;

typedef enum _UART_STOP_BITS_e_
{
    UART_STOP_BITS_1 = 1,
    UART_STOP_BITS_2,

    UART_STOP_BITS_MAX,
} UART_STOP_BITS_e;

typedef enum _UART_FLOW_CTRL_e_
{
    UART_FLOW_CTRL_NONE = 1,
    UART_FLOW_CTRL_RTS_CTS,
    UART_FLOW_CTRL_XON_XOFF,

    UART_FLOW_CTRL_MAX,
} UART_FLOW_CTRL_e;

typedef enum _UART_PARITY_CHK_e_
{
    UART_PARITY_CHK_NONE = 1,  //无校验
    UART_PARITY_CHK_ODD,       //奇校验
    UART_PARITY_CHK_EVEN,      //偶校验
    UART_PARITY_CHK_MARK,      //标记校验
    UART_PARITY_CHK_SPACE,     //空格校验

    UART_PARITY_CHK_MAX,
} UART_PARITY_CHK_e;

typedef struct _BSP_UART_CFG_s_
{
    BOOL              isEnable;
    SINT32            iFd;
    CHAR              szPath[256];
    UART_BAUD_RATE_e  enBaudRate;
    UART_DATA_BITS_e  enDataBits;
    UART_STOP_BITS_e  enStopBits;
    UART_PARITY_CHK_e enParityChk;
    UART_FLOW_CTRL_e  enFlowCtrl;
} BSP_UART_CFG_s;

typedef struct _USER_UART_CFG_s_
{
    BOOL              isEnable;
    SINT32            iFd;
    CHAR              szPath[256];
    UART_BAUD_RATE_e  enBaudRate;
    UART_DATA_BITS_e  enDataBits;
    UART_STOP_BITS_e  enStopBits;
    UART_PARITY_CHK_e enParityChk;
    UART_FLOW_CTRL_e  enFlowCtrl;
} USER_UART_CFG_s;

extern ULONG BspUart_Open(IN BSP_UART_CHANNEL_e enChan, INOUT SINT32 *piFd);
extern ULONG BspUart_Read(IN BSP_UART_CHANNEL_e enChan, INOUT UINT8 *pucBuf, IN SINT32 iLen);
extern ULONG BspUart_Write(IN BSP_UART_CHANNEL_e enChan, INOUT UINT8 *pucBuf, IN SINT32 iLen);

#ifdef __cplusplus
}
#endif

#endif
